package mg.engine.architecture.item.object;

import mg.engine.architecture.item.MGItem;
import mg.engine.architecture.layer.MGLayer;
import mg.engine.physics.MGEngine;
import mg.system.event.MGEvent;

public class MGObject extends MGItem
{
	public short	role_id		= 0;
	public short	script_id	= 0;

	public short[]	frame_data	= null;

	public short	speed		= 0;

	public short	type		= 0;

	public short	now_action	= 0;
	public short	now_frame	= 0;

	private int		countTime	= 0;

	public MGObject(MGLayer Layer, short[] data, int cell_width, int cell_height)
	{
		super(Layer);
		role_id = data[0];
		script_id = data[1];
		position_y = (data[2] * cell_height) + (cell_height >> 1);
		position_x = (data[3] * cell_width) + (cell_width >> 1);
		frame_data = new short[data[4]];

		for (int i = 0; i < frame_data.length; i++)
		{
			frame_data[i] = data[i + 5];
		}
		speed = data[frame_data.length + 5];
		type = data[frame_data.length + 6];
		width = data[frame_data.length + 7];
		height = data[frame_data.length + 8];
	}

	public void update()
	{
		countTime++;
		if (countTime == speed)
		{
			countTime = 0;
			now_frame = (short) (MGEngine.time.getTime(5) % frame_data[now_action]);
		}
	}

	public boolean handleEvent(MGEvent event)
	{
		return false;
	}
}
